﻿using ScFramework.Core;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public  partial class SFuncBase :SComponent
{
    [PureValueAtrribute]
    public string FuncName="";
    [PureValueAtrribute]
    public string FuncInfo="";
    [PureValueAtrribute]
    public KeyCode Key;

    public override void SInit()
    {
        base.SInit();
    }
    public override void SStart()
    {
        base.SStart();
    }
    public override void SOnEnable(object args = null)
    {
        base.SOnEnable(args);
        lastKeyOn = false;
        thisKeyOn = false;
    }
    public virtual void LocalKeyDown()
    {

    }
    bool thisKeyOn = false;
    protected bool lastKeyOn = false;
    public override void SFixedUpdate()
    {
        base.SFixedUpdate();
        if (lastKeyOn == true && thisKeyOn == false)
        {
            ServerKeyUp();
            LocalKeyUp();
        }
        lastKeyOn = thisKeyOn;
        thisKeyOn = false;
    }
    public virtual void LocalKeyOn()
    {
        thisKeyOn = true;
        if (lastKeyOn == false)
        {
            LocalKeyDown();
        }
        
    }
    public virtual void LocalKeyUp() 
    {
    
    }
    public virtual void ServerKeyDown()
    {

    }
    public virtual void ServerKeyOn()
    {
        thisKeyOn = true;
        if (lastKeyOn == false)
        {
            ServerKeyDown();
        }
    }
    public virtual void ServerKeyUp()
    {

    }

}

public abstract class SRigidFunc<T> : SFuncBase where T:Component
{
    [HideInInspector]
    public T rigidComp;
    public override void SetRigid(Rigidbody2D r)
    {
        base.SetRigid(r);
        Debug.Assert(Rigid != null);
        rigidComp=Rigid.gameObject.AddComponent<T>();
        Debug.Assert(rigidComp != null);
    }
    public override void ClearRigid()
    {
        base.ClearRigid();
        if (rigidComp != null)
        {
            GameObject.Destroy(rigidComp);
        }
    }
}


